﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ReactiveCode.Observables
{
    [TestClass]
    public class ExtensionTests
    {
        [TestMethod]
        public void SubscribeIf()
        {
            var source = new Variable<int>();
            var test = new Variable<bool>();

            List<int> actual = new List<int>();
            source.SubscribeIf(test).DistinctUntilChanged().Subscribe(actual.Add);

            source.Value = 1;
            source.Value = 2;

            test.Value = true;

            source.Value = 3;
            source.Value = 4;

            test.Value = false;

            source.Value++;
            source.Value++;

            int[] expected = {2, 3, 4 };
            CollectionAssert.AreEqual(expected, actual);
        }
    }
}
